/*    */ package cn.zzuisa.news.repository.dao;

/*    */
/*    */ import cn.zzuisa.news.entity.Recruit;
/*    */ import cn.zzuisa.news.repository.RecruitRepository;
/*    */ import cn.zzuisa.news.util.JDBCUtil;
/*    */ import java.sql.Connection;
/*    */ import java.sql.PreparedStatement;
/*    */ import java.sql.ResultSet;
/*    */ import java.sql.SQLException;
/*    */ import java.sql.Statement;
/*    */ import java.util.ArrayList;
/*    */ import java.util.List;

/*    */
/*    */
/*    */
/*    */ public class RecruitDAO/*    */ implements RecruitRepository
/*    */ {
	Connection conn = null;
	Statement statement = null;
	ResultSet resultSet = null;
	PreparedStatement preparedStatement = null;

	/*    */ public List<Recruit> list(String major) {
		/* 20 */ System.out.println("kaishi:" + major);
		/* 21 */ conn = JDBCUtil.getConnection();
		/* 22 */ statement = null;
		/* 23 */ resultSet = null;
		/* 24 */ System.out.println("kaishi2:" + major);
		/* 25 */ String sql = null;
		/* 26 */ sql = (major != null) ? ("select * from recruit where type = '" + major + "' order by id desc  ") :
		/* 27 */ "select * from recruit order by id desc";

		if (major != null && major.equals("all")) {
			sql = "select * from recruit where status = 1";
		}
		/*    */ try {
			/* 29 */ statement = conn.createStatement();
			/* 30 */ resultSet = statement.executeQuery(sql);
			/* 31 */ List<Recruit> recruits = new ArrayList<Recruit>();
			/* 32 */ while (resultSet.next()) {
				/* 33 */ Recruit recruit = new Recruit();
				/* 34 */ recruit.setNote(resultSet.getString("note"));
				/* 35 */ recruit.setCreatetime(resultSet.getTimestamp("createtime"));
				/* 36 */ recruit.setQq(resultSet.getString("qq"));
				/* 37 */ recruit.setPhone(resultSet.getString("phone"));
				/* 38 */ recruit.setId(Integer.valueOf(resultSet.getInt("id")));
				/* 39 */ recruit.setMajor(resultSet.getString("major"));
				/* 40 */ recruit.setIp(resultSet.getString("ip"));
				/* 41 */ recruit.setName(resultSet.getString("name"));
				/* 42 */ recruit.setSex(resultSet.getString("sex"));
				/* 43 */ recruit.setSid(resultSet.getString("sid"));
				/* 44 */ recruit.setStatus(Integer.valueOf(resultSet.getInt("status")));
				/* 45 */ recruit.setType(resultSet.getString("type"));
				/* 46 */ recruits.add(recruit);
				/*    */ }
			/* 48 */ System.out.println("recruittttttt" + recruits);
			/* 49 */ return recruits;
			/*    */ }
		/* 51 */ catch (SQLException e) {
			/*    */
			/* 53 */ e.printStackTrace();
			/*    */ } finally {
			/*    */ try {
				/* 56 */ JDBCUtil.close(conn, statement, resultSet);
				/* 57 */ } catch (Exception e) {
				/*    */
				/* 59 */ e.printStackTrace();
				/*    */ }
			/*    */ }
		/* 62 */ return null;
		/*    */ }

	/*    */
	/*    */
	/*    */ public boolean updateStatus(Integer id, Integer status) {
		/* 67 */ conn = JDBCUtil.getConnection();
		/* 68 */ preparedStatement = null;
		/* 69 */ resultSet = null;
		/* 70 */ int flag = 0;
		/* 71 */ String sql = "UPDATE recruit SET status=? where id = ?";
		/*    */ try {
			/* 73 */ preparedStatement = conn.prepareStatement(sql);
			/* 74 */ preparedStatement.setInt(1, status.intValue());
			/* 75 */ preparedStatement.setInt(2, id.intValue());
			/* 76 */ flag = preparedStatement.executeUpdate();
			/* 77 */ } catch (SQLException e) {
			/*    */
			/* 79 */ e.printStackTrace();
			/*    */ } finally {
			/*    */ try {
				/* 82 */ JDBCUtil.close(conn, preparedStatement, resultSet);
				/* 83 */ } catch (Exception e) {
				/*    */
				/* 85 */ e.printStackTrace();
				/*    */ }
			/*    */ }
		/* 88 */ return (flag > 0);
		/*    */ }
	/*    */ }

/*
 * Location:
 * /Users/frank/Desktop/admin/WEB-INF/classes/!/cn/zzuisa/news/repository/dao/
 * RecruitDAO.class Java compiler version: 8 (52.0) JD-Core Version: 1.0.7
 */